//
//  VC2Siwtch.swift
//  ChapterAll
//
//  Created by Kevin on 2020/4/21.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VC2Switch: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let siwtch = UISwitch()
        siwtch.frame.origin = CGPoint(x: 20, y: 100)
        print("\(siwtch.bounds.width) \(siwtch.bounds.height)")
        siwtch.onTintColor = UIColor.orange
        siwtch.tintColor = UIColor.red
        siwtch.thumbTintColor = UIColor.blue
        siwtch.addTarget(self, action: #selector(clickSwith(ui:)), for: .valueChanged)
        view.addSubview(siwtch)
        
        let siwtch1 = UISwitch(frame: CGRect(x: 20, y: 300, width: 200, height: 50))
        siwtch1.backgroundColor = UIColor.red
        print("\(siwtch1.bounds.width) \(siwtch1.bounds.height)")
        view.addSubview(siwtch1)
    }
    
    @objc func clickSwith(ui:UISwitch) -> Void {
        if ui.isOn {
            view.backgroundColor = UIColor.gray
        }else {
            view.backgroundColor = UIColor.green
        }
    }
    
}
